package me.leon.ade

import android.content.Context
import android.content.Intent
import android.util.Log
import android.view.View
import me.leon.ade.databinding.ActivityWebViewBinding

class WebViewActivity : AbsBindingActivity<ActivityWebViewBinding>() {

    val v by lazy { View(this) }

    override fun ActivityWebViewBinding.init() {
        var file = "file:///android_asset/111.pdf"
        // 支持跨域文件
        file = "https://www.who.int/mental_health/evidence/editors_statement_chinese.pdf"

        // 不支持跨域文件
        //        file =
        //
        // "https://zjseal.zjzwfw.gov.cn/api/tyyzpt/sign/downloadSignFile/d3ca844624ce11ebba2e6c92bfce1812.pdf"
        web.settings.run {
            javaScriptEnabled = true
            // 允许跨域
            allowUniversalAccessFromFileURLs = true
        }

        //        web.loadUrl("file:///android_asset/web/viewer.html?file=$file")
        //        web.loadUrl("https://mozilla.github.io/pdf.js/web/viewer.html?file=$file")
        web.loadUrl("file:///android_asset/viewer2.12.html?file=$file")
        //        web.loadUrl("http://debugtbs.qq.com/")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d("Leon666", v.toString())
    }

    companion object {
        fun start(context: Context) {
            context.startActivity(
                Intent(context, WebViewActivity::class.java).apply {
                    addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                }
            )
        }
    }
}
